const Koa = require("koa")
const router = require("koa-router")()
const koaStaticCache = require("koa-static-cache")
const koaBody = require("koa-body")

const app = new Koa()

app.use(koaStaticCache({
  prefix: "/public",
  dir: "./public"
}))

router.post("/uploadImg", koaBody({
  // 设置对否对上传文件解析
  multipart: true,
  // 对上传文件的设置
  formidable: {
    // 设置上传文件保存位置
    uploadDir: "./public/uploads",
    // 保持原数据的扩展名
    keepExtensions: true,
  }
}), async (ctx, next) => {
  console.log(ctx.request.files)
  ctx.body = "成功"
})

app.use(router.routes())

app.listen(8080)
console.log("run on http://localhost:8080")
